package vru;


import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * JUnit test to test keeping distance.
 * @author Russell Vea for ICS 314
 */
public class TwentyTestDistance extends RobotTestBed {

  /** The number of kills.*/
  private int avoidances = 0;
  double distance = 0.0;
  private int rounds = 0;
  /** Set to true to print out amount of kills.*/
  private boolean debug = true;
  private int total = 0;

  /**
   * Specifies that SittingDuck and Destroyer are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() { 
    return "rvu.Lessthan20charsyeah,sample.RamFire";
  }

  /*
  public void onRoundStarted(RoundStartedEvent e ) { 
    this.avoidances = 0;
    this.total = 0;
  }*/
  
  /**
   * This test runs for 10 rounds.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }


  /**
   * @param e Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent e) { 
    IRobotSnapshot me = e.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot enemy = e.getTurnSnapshot().getRobots()[1];
    this.distance = 
        //x^2
        Math.pow((enemy.getY() - me.getY()), 2)   
        //y^2
      + Math.pow((enemy.getX() - me.getX()), 2);  
    //sqrt(x^2 + y^2) = c, check to see if its greater than 200 
    if (Math.sqrt(distance) > 200) {  
      this.avoidances++;
    }
    //keep track of total turns
    this.total++;
  }

  /**
   * After the battle, check to see that we've visited the corners.
   *
   * @param e Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent e) {
    if (this.debug) { 
      System.out.println("this.rounds: " + this.rounds + 
                         " %: " + ((double)this.avoidances / (double)this.total));
    }
    assertTrue("Killed oppononent at leasta 70% of the time", 
              ((double)this.avoidances / (double)this.total) > 0.7);
  }
  
}
